package com.woniuxy.propertyjava.controller;


import com.woniuxy.propertyjava.entity.Housinginformation;
import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.ResponseResult;
import com.woniuxy.propertyjava.service.HousinginformationService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Housinginformation)表控制层
 *
 * @author makejava
 * @since 2022-07-04 19:33:22
 */
@RestController
public class HousinginformationController {
    /**
     * 服务对象
     */
    @Resource
    private HousinginformationService housinginformationService;

    /**
     * 分页查询
     *
     * housinginformation 筛选条件
     * pageRequest      分页对象
     *  查询结果
     */
//    @GetMapping
//    public ResponseEntity<Page<Housinginformation>> queryByPage(Housinginformation housinginformation, PageRequest pageRequest) {
//        return ResponseEntity.ok(this.housinginformationService.queryByPage(housinginformation, pageRequest));
//    }
      @PostMapping("/housinginformation/{pageIndex}/{pageSize}")
      public ResponseResult<PageBean<Housinginformation>> getAllhouseinformation(
              @PathVariable("pageIndex") int pageIndex,
              @PathVariable("pageSize") int pageSize,
              @RequestBody Housinginformation housinginformation){
          PageBean<Housinginformation> pageBean=housinginformationService.queryByCondition(pageIndex, pageSize,housinginformation);
          return new ResponseResult<>(200, "ok", pageBean);
      }
//    /**
//     * 通过主键查询单条数据
//     *
//     * @param id 主键
//     * @return 单条数据
//     */
//    @GetMapping("{id}")
//    public ResponseEntity<Housinginformation> queryById(@PathVariable("id") Integer id) {
//        return ResponseEntity.ok(this.housinginformationService.queryById(id));
//    }
//
    /**
     * 新增数据
     *
     * @param housinginformation 实体
     * @return 新增结果
     */
    @PostMapping("/housinginformation")
    public ResponseResult<Housinginformation> add(@RequestBody Housinginformation housinginformation) {
        housinginformationService.insert(housinginformation);
        return new ResponseResult<>(200, "ok", null);
    }

    /**
     * 编辑数据
     *
     * @param housinginformation 实体
     * @return 编辑结果
     */
    @PutMapping("/housinginformation")
    public ResponseResult<Housinginformation> edit(@RequestBody Housinginformation housinginformation) {
        housinginformationService.update(housinginformation);
        return new ResponseResult<>(200, "ok", null);
    }

    /**
     * 删除数据
     *
     *  id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("housinginformation/{hiid}")
    public ResponseResult<Boolean> deleteById(@PathVariable("hiid") Integer hiid) {
        return new ResponseResult<>(200, "ok", housinginformationService.deleteById(hiid));
    }

}

